package org.makcro.sms.services.chat.web.client.widgets;

import java.util.ArrayList;
import java.util.List;

import org.makcro.sms.services.chat.web.shared.dto.HistoryItemDto;

import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;

public class AllMessagesPanel extends ContentPanel {

	private Grid<HistoryItemDto>		grid;
	private ListStore<HistoryItemDto>	store;
	private List<ColumnConfig>			columns;

	public AllMessagesPanel() {

		initComponents();
	}

	public void initComponents() {
		setHeading( "Moje odgovorene poruke" );
		setLayout( new FitLayout() );
		add( getGrid() );
	}

	public Grid<HistoryItemDto> getGrid() {
		if ( grid == null ) {
			grid = new Grid<HistoryItemDto>( getStore(), new ColumnModel( getColumns() ) );
			grid.setAutoExpandColumn( "questoin" );
		}
		return grid;
	}

	public ListStore<HistoryItemDto> getStore() {
		if ( store == null ) {
			store = new ListStore<HistoryItemDto>();
		}
		return store;
	}

	public List<ColumnConfig> getColumns() {
		if ( columns == null ) {
			columns = new ArrayList<ColumnConfig>();
			ColumnConfig column = new ColumnConfig( "questoin", "Poruka", 300 );
			column.setRenderer( new HistoryCellRenderer() );
			columns.add( column );
		}
		return columns;
	}
}
